#include <iostream>
#include <algorithm>
#include <cstdio>
#include <array>
#include <vector>
#include <random>
#include <chrono>
#include <bitset>
#include "game.h"
using namespace std;
#ifdef ONLINE_JUDGE

#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 23], *p1 = buf, *p2 = buf, ubuf[1 << 23], *u = ubuf;

#endif
int read() {
    int p = 0, flg = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') flg = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        p = p * 10 + c - '0';
        c = getchar();
    }
    return p * flg;
}
void write(int x) {
    if (x < 0) {
        x = -x;
        putchar('-');
    }
    if (x > 9) {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}
bool _stmer;

mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());

const int N = 5005;

bitset <N> vis;

void SA(vector <int> &ans, int n, int limit) {
    if (!limit) return;
    int _ans = count(ans); limit--;
    while (limit) {
        int x = rnd() % n, y = rnd() % n;
        swap(ans[x], ans[y]);
        int res = count(ans); limit--;
        if (_ans < res) _ans = res;
        else swap(ans[x], ans[y]);
    }
}

vector <int> guess(int n, int limit) {
    vector <int> ans;
    ans.resize(n);
    for (int i = 1; i <= n; i++)
        ans[i - 1] = i;
    /* limit -= 100; */
    /* SA(ans, n, 100); */
    int lst = count(ans);
    for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        /* if (i == 2) puts("#@!!#@!#"); */
        int res = lst; limit--;
        vector <int> isl0, isl1;
        for (int j = i + 1; j < n; j++) {
            if (vis[j]) continue;
            swap(ans[i], ans[j]);
            int now = count(ans); limit--;
            if (now == res - 2) {
                vis[i] = 1, swap(ans[i], ans[j]);
                break;
            }
            if (now == res - 1) isl0.push_back(j);
            if (now == res + 1) isl1.push_back(j);
            if (now == res + 2) {
                vis[i] = 1, vis[j] = 1;
                lst = now;
                break;
            }
            swap(ans[i], ans[j]);
        }
        if (vis[i]) continue;
        if (isl1.size() != 2) { vis[i] = 1; continue; }
        int p1 = isl1.front(), p2 = isl1.back();
        swap(ans[i], ans[p1]), swap(ans[p1], ans[p2]);
        for (auto k : isl0) vis[k] = 1;
        int now = count(ans); limit--;
        lst = now;
        if (now == res + 3) {
            vis[i] = vis[p1] = vis[p2] = 1;
            continue;
        }
        if (now == res + 2) {
            vis[i] = vis[p2] = 1;
            continue;
        }
        if (now == res) {
            swap(ans[p1], ans[p2]), swap(ans[i], ans[p1]);
            swap(ans[i], ans[p2]), swap(ans[p1], ans[p2]);
            vis[i] = vis[p1] = 1;
            lst = count(ans);
            continue;
        }
    }
    /* limit--; */
    /* for (auto k : ans) */
        /* write(k), putchar(32); */
    /* puts("@"); */
    /* if (count(ans) != n) cerr << "bug" << endl; */
    return ans;
}
bool _edmer;
